In a programmable logic controller (PLC) for use in a factory automation (FA) control system, a central processing unit (CPU) that controls the overall PLC exchanges data with a network unit using shared memory. The network unit is one of functional units and receives data from another device via a network.
When the CPU reads data from the shared memory while the network unit updates data in the shared memory, the data read by the CPU is a mix of data received by the network unit and written to the shared memory at the previous cycle time and data received by the network unit at the current cycle time. The data received by the network unit may need a certain chunk of data to be meaningful data, and thus in the above case, a single read of data that is to be read out at one time, that is, data consistency, cannot be guaranteed.
To address this disadvantage, Patent Literature 1 discloses using a flag to provide exclusive control that does not allow the CPU and the functional unit to concurrently read and write data from and to the shared memory.
For example, a known type of exclusive control uses a flag as follows. Access to the shared memory is expressed in three states: “0”, indicating that a write by the network unit is allowed; “1”, indicating that a read by the CPU is allowed; and “2”, indicating that the CPU is in a read operation. The value of the flag that indicates these three states are changed from “0” to “1, from “1” to “2”, or from “2” to “0”. The CPU and the network unit access the shared memory if the value of the flag indicates that the access to the shared memory is allowed.